//class Solution {
//public:
//    ListNode* reverseList(ListNode* list) {
//        ListNode* newhead = new ListNode, * cur = list;
//        while (cur) {
//            auto tmp = cur->next;
//            cur->next = newhead->next;
//            newhead->next = cur;
//            cur = tmp;
//        }
//        cur = newhead->next;
//        delete cur;
//        return prev
//    }
//    ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
//        ListNode* cur1 = reverseList(l1), * cur2 = reverseList(l2)
//            ListNode * newhead = new ListNode, *prev = nullptr;
//        int bit = 0;
//        while (cur1 || cur2 || bit) {
//            if (cur1) {
//                bit += cur1->val;
//                cur1 = cur1->next;
//            }
//
//            if (cur2) {
//                bit += cur2->val;
//                cur2 = cur2->next;
//            }
//
//            ListNode* node = new ListNode(bit % 10)
//                bit /= 10;
//            prev->next = node;
//            prev = prev->next;
//        }
//        prev->next = nullptr;
//        prev = newhead->next;
//        delete newhead;
//        return reverseList(prev);
//    }
//};




class Solution {
public:
    ListNode* swapPairs(ListNode* head) {
        if (head == nullptr || head->next == nullptr) return head;
        ListNode* newhead = new ListNode(), * prev = newhead;
        ListNode* cur = head;
        while (cur && cur->next)
        {
            ListNode* next = cur->next, * nnext = next->next;
            prev->next = next;
            next->next = cur;
            prev = cur;

            cur = nnext;
        }
        prev->next = cur;

        prev = newhead->next;
        delete newhead;
        return prev;
    }
};